<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/3/31
 * Time: 17:03
 */

namespace common\sources\write\buydepositrecord;

use Yii;
use common\models\craftsman\BuyDepositRecord;

class BuyDepositRecordAccess implements IBuyDepositRecordAccess
{
    public function addDepositRecord_push($data) {
        $depositRecord = new BuyDepositRecord();
        $depositRecord->buy_id = $data['push_role_id'];
        $depositRecord->income = $data['deposit'];
        $depositRecord->balance = $data['push_deposit'];
        $depositRecord->remark = $data['remark'];
        $depositRecord->operatorId = $data['operatorId'];
        $depositRecord->task_id = $data['task_id'];
        $depositRecord->img_url = $data['img_url'];
        $depositRecord->type = $data['type'];
        $depositRecord->action_type = 1;//充值
        $depositRecord->create_time = time();
        $depositRecord->update_time = time();
        $depositRecord->save();
    }

	public function addBuyDepositRecord($data) {
		return Yii::$app->db->createCommand()->insert('buy_deposit_record', [
			'buy_id'         => $data['buy_id'],
			'task_commod_id' => isset($data['task_commod_id']) ? $data['task_commod_id'] : 0,
			'task_id'        => isset($data['task_id']) ? $data['task_id'] : 0,
			"task_order_id"  => isset($data['task_order_id']) ? $data['task_order_id'] : 0,
			"task_order_num" => isset($data['task_order_num']) ? $data['task_order_num'] : '',
			'expend'         => $data['expend'],
			'income'         => $data['income'],
			'balance'        => $data['balance'],
			'freeze_change' => isset($data['freeze_change']) ? $data['freeze_change'] : 0,
			'freeze_balance'=> isset($data['freeze_balance']) ? $data['freeze_balance'] : 0,
			'remark'         => $data['remark'],
			'type'           => $data['type'],
			"operatorId"     => isset($data['operatorId']) ? $data['operatorId'] : '',
			'create_time'    => time(),
			'auditor_time'   => isset($data['auditor_user']) ? time() : '',
			'auditor_user'   => isset($data['auditor_user']) ? $data['auditor_user'] : '',
			'end_time'       => isset($data['end_user']) ? time() : '',
			'end_user'       => isset($data['end_user']) ? $data['end_user'] : '',
		])->execute();
	}
}